# coding=utf-8

from flask import Blueprint, request, jsonify, json, make_response, redirect, g
from common.models.Food import FoodType
from common.libs.user.UserLibs import UserLibs
from common.libs.Helper import ops_render
from common.libs.UrlManager import UrlManager
from application import app,db
from web.controllers.BaseControllerHelper import *
from .Helper import *

route_api_food_type = Blueprint( 'food_type_page',__name__ )

@route_api_food_type.route("/get_all", methods=["GET"])
def get_all():
    resp = gene_response(msg="OK")
    food_type_list = FoodType.query.filter_by().all()
    data_list = []
    if food_type_list :
        for food_type in food_type_list :
            temp_type = create_food_type_json(food_type, ["id", "name"])
            data_list.append(temp_type)
            resp = gene_response(code=200, msg="OK", data=data_list)
    else :
        resp = gene_response(code=-1, msg="暂无信息", data=data_list)
    return jsonify( resp )



